package com.tencent.sr.iris.basic.saas.restapi.group;


import com.tencent.sr.iris.activity.interfaces.request.group.AdvisorGroupTaskRequest;
import com.tencent.sr.iris.activity.interfaces.request.operate.*;
import com.tencent.sr.iris.activity.interfaces.response.group.AdvisorBoardResponse;
import com.tencent.sr.iris.activity.interfaces.response.group.GroupTaskPaginationResponse;
import com.tencent.sr.iris.activity.interfaces.response.group.operate.*;
import com.tencent.sr.iris.basic.saas.common.enums.TaskTargetEvaluationEnum;
import com.tencent.sr.iris.basic.saas.common.enums.YesOrNoEnum;
import com.tencent.sr.iris.basic.saas.dependency.group.OperateTaskBoardDependency;
import com.tencent.sr.iris.basic.saas.service.group.ExportOperateService;
import com.tencent.sr.iris.basic.saas.interfaces.response.export.ExportResponse;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import com.tencent.sr.rmall.springbootstarter.authtoken.localbean.AppUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Slf4j
@Api(tags = "运营-团长任务看板", value = "运营-团长任务看板")
@RestController
@RequestMapping(value = {"/iris/activity/saas/v1/grouptask/operate"})
public class OperateBoardController {
    @Resource
    private OperateTaskBoardDependency operateTaskBoardDependency;
    @Resource
    private AppUser appUser;
    @Resource
    private ExportOperateService exportOperateService;

    @PostMapping("/queryOperateBoardInvite")
    @ApiOperation(value = "运营平台-邀新有礼")
    public HttpResult<PaginationResponse<OperateBoardInviteResponse>> queryOperateBoardInvite(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return operateTaskBoardDependency.queryOperateBoardInvite(request);
    }

    @PostMapping("/queryOperateBoardSprint")
    @ApiOperation(value = "运营平台-冲刺赛")
    public HttpResult<PaginationResponse<OperateBoardSprintResponse>> queryOperateBoardSprint(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return operateTaskBoardDependency.queryOperateBoardSprint(request);
    }

    @PostMapping("/queryOperateBoardCommission")
    @ApiOperation(value = "运营平台-佣金回滚")
    public HttpResult<PaginationResponse<OperateBoardCommissionResponse>> queryOperateBoardCommission(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return operateTaskBoardDependency.queryOperateBoardCommission(request);
    }

    @PostMapping("/queryOperateFirstOrder")
    @ApiOperation(value = "运营平台-粉丝首单任务")
    public HttpResult<PaginationResponse<OperateBoardFirstOrderResponse>> queryOperateFirstOrder(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return operateTaskBoardDependency.queryOperateFirstOrder(request);
    }

    @PostMapping("/queryOperateBoard")
    @ApiOperation(value = "运营平台-一级页面")
    public HttpResult<PaginationResponse<AdvisorBoardResponse>> queryOperateBoard(
            @Validated @RequestBody PaginationRequest<AdvisorGroupTaskRequest> request) {
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return operateTaskBoardDependency.queryOperateBoard(request);
    }

    @PostMapping("/queryOperateSecondBoard")
    @ApiOperation(value = "运营平台-二级页面")
    public HttpResult<GroupTaskPaginationResponse<OperateSecondBoardResponse>> queryOperateSecondBoard(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return operateTaskBoardDependency.queryOperateSecondBoard(request);
    }

    @PostMapping("/queryOperateThirdBoard")
    @ApiOperation(value = "运营平台-三级页面")
    public HttpResult<PaginationResponse<OperateThirdBoardResponse>> queryOperateThirdBoard(
            @Validated @RequestBody PaginationRequest<OperateBoardThirdRequest> request) {
        request.getQueryCriteria().setSaasId(appUser.getSaasId());
        return operateTaskBoardDependency.queryOperateThirdBoard(request);
    }

    @PostMapping("/operateBoardStatistics")
    @ApiOperation(value = "运营平台-一级统计")
    public HttpResult<OperateBoardStatisticsResponse> operateBoardStatistics(
            @Validated @RequestBody OperateBoardStatisticsRequest request) {
        List<Integer> taskTargetEvaluation = request.getTaskTargetEvaluation();
        if (CollectionUtils.isNotEmpty(taskTargetEvaluation) &&
                taskTargetEvaluation.contains(TaskTargetEvaluationEnum.TRAINEE_LEVEL_UP.getCode())) {
            taskTargetEvaluation.add(TaskTargetEvaluationEnum.MEMBER_LEVEL_UP.getCode());
            taskTargetEvaluation.add(TaskTargetEvaluationEnum.SENIOR_LEVEL_UP.getCode());
        }
        return HttpResult.succ(operateTaskBoardDependency.operateBoardStatistics(request));
    }

    @PostMapping("/taskGroupSpecialStageLists")
    @ApiOperation(value = "团推团-任务阶段")
    public HttpResult<List<SpecialStageListsResponse>> taskGroupSpecialStageLists(
            @Validated @RequestBody SpecialStageListsRequest request) {
        return HttpResult.succ(operateTaskBoardDependency.taskGroupSpecialStageLists(request));
    }

    @PostMapping("/export/operateBoard")
    @ApiOperation(value = "运营平台-一级页面导出")
    public HttpResult<ExportResponse> operateBoard(
            @Validated @RequestBody PaginationRequest<AdvisorGroupTaskRequest> request) {
        AdvisorGroupTaskRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateBoard(queryCriteria));
    }

    @PostMapping("/export/operateBoardInvite")
    @ApiOperation(value = "运营平台-邀新有礼导出")
    public HttpResult<ExportResponse> operateBoardInvite(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        OperateBoardRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateInviteBoard(queryCriteria));
    }

    @PostMapping("/export/operateBoardSprint")
    @ApiOperation(value = "运营平台-冲刺赛导出")
    public HttpResult<ExportResponse> operateBoardSprint(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        OperateBoardRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateSprintBoard(queryCriteria));
    }

    @PostMapping("/export/operateCommission")
    @ApiOperation(value = "运营平台-佣金回滚导出")
    public HttpResult<ExportResponse> operateBoardCommission(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        OperateBoardRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateCommissionBoard(queryCriteria));
    }

    @PostMapping("/export/operateFirstOrder")
    @ApiOperation(value = "运营平台-粉丝首单任务导出")
    public HttpResult<ExportResponse> operateBoardFirstOrder(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        OperateBoardRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateFirstOrderBoard(queryCriteria));
    }

    @PostMapping("/export/operateNormalBoard")
    @ApiOperation(value = "运营平台-普通团推团任务导出")
    public HttpResult<ExportResponse> operateNormalBoard(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        OperateBoardRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateNormalBoard(queryCriteria));
    }

    @PostMapping("/export/operateSpecialBoard")
    @ApiOperation(value = "运营平台-特殊团推团任务导出")
    public HttpResult<ExportResponse> operateSpecialBoard(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        OperateBoardRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateSpecialBoard(queryCriteria));
    }

    @PostMapping("/export/operateNormalBoardThird")
    @ApiOperation(value = "运营平台普通团推团三级页面导出")
    public HttpResult<ExportResponse> operateNormalBoardThird(
            @Validated @RequestBody PaginationRequest<OperateBoardThirdRequest> request) {
        OperateBoardThirdRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateNormalBoardThird(queryCriteria));
    }

    @PostMapping("/export/operateSpecialBoardThird")
    @ApiOperation(value = "运营平台特殊团推团三级页面导出")
    public HttpResult<ExportResponse> operateSpecialBoardThird(
            @Validated @RequestBody PaginationRequest<OperateBoardThirdRequest> request) {
        OperateBoardThirdRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateSpecialBoardThird(queryCriteria));
    }

    @PostMapping("/export/unJoinTask")
    @ApiOperation(value = "导出未报名团长")
    public HttpResult<ExportResponse> unJoinTask(
            @Validated @RequestBody PaginationRequest<UnJoinTaskRequest> request){
        UnJoinTaskRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        if (Objects.equals(queryCriteria.getIsAdviser(), YesOrNoEnum.YES.getValue())) {
            queryCriteria.setUserTutorUid(appUser.getUid());
        }

        return HttpResult.succ(exportOperateService.unJoinTask(queryCriteria));
    }


    @PostMapping("/export/operateRankBoard")
    @ApiOperation(value = "运营平台-排行榜任务导出")
    public HttpResult<ExportResponse> operateRankBoard(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        OperateBoardRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateRankBoard(queryCriteria));
    }

    @PostMapping("/export/operateRankBoardThird")
    @ApiOperation(value = "运营平台排行榜三级页面导出")
    public HttpResult<ExportResponse> operateRankBoardThird(
            @Validated @RequestBody PaginationRequest<OperateBoardThirdRequest> request) {
        OperateBoardThirdRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateRankBoardThird(queryCriteria));
    }

    @PostMapping("/export/operateSpecialSprintBoard")
    @ApiOperation(value = "运营平台-特邀会员冲刺赛任务导出")
    public HttpResult<ExportResponse> operateSpecialSprintBoard(
            @Validated @RequestBody PaginationRequest<OperateBoardRequest> request) {
        OperateBoardRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateSpecialSprintBoard(queryCriteria));
    }

    @PostMapping("/export/operateSpecialSprintBoardThird")
    @ApiOperation(value = "运营平台特邀会员冲刺赛三级页面导出")
    public HttpResult<ExportResponse> operateSpecialSprintBoardThird(
            @Validated @RequestBody PaginationRequest<OperateBoardThirdRequest> request) {
        OperateBoardThirdRequest queryCriteria = request.getQueryCriteria();
        queryCriteria.setSaasId(appUser.getSaasId());
        return HttpResult.succ(exportOperateService.operateSpecialSprintBoardThird(queryCriteria));
    }

}
